import 'dart:collection';

import '../extentions/datetime_extensions.dart';
import 'api_doc_summary.dart';

part 'log.dart';

abstract class Logger {
  static void save(dynamic log) {
    if (log is Log) {
      _storage.save(log);
    } else if (log is String) {
      _storage.save(NormalLog(log));
    }
  }

  static List<Log> getAll() => _storage.getAll();

  static bool contains(Log log) => _storage.contains(log);

  static _LogStorage _storage = _LogStorage();
  static List<Log>? remoteLogs;
}

class _LogStorage {
  final int maxCount;
  Queue<Log> items = new Queue();

  _LogStorage({this.maxCount = 100});

  List<Log> getAll() {
    return items.toList();
  }

  bool save(Log log) {
    if (items.length >= maxCount) {
      items.removeFirst();
    }
    items.add(log);
    return true;
  }

  bool contains(Log log) {
    return items.contains(log);
  }
}
